home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / bitmap / bitmapte.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  19.2 KB  |  614 lines

  1. VERSION 2.00
  2. Begin Form BitmapTest 
  3.    BackColor       =   &H00FFFFFF&
  4.    Caption         =   "Bitmaps, Device Contexts, Image and Picture Properties, Oh My!"
  5.    ClientHeight    =   5445
  6.    ClientLeft      =   825
  7.    ClientTop       =   1335
  8.    ClientWidth     =   9165
  9.    Height          =   5850
  10.    Left            =   765
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   5445
  14.    ScaleWidth      =   9165
  15.    Top             =   990
  16.    Width           =   9285
  17.    Begin CommandButton Quit 
  18.       Caption         =   "I'VE HAD IT!"
  19.       Default         =   -1  'True
  20.       FontBold        =   -1  'True
  21.       FontItalic      =   0   'False
  22.       FontName        =   "MS Sans Serif"
  23.       FontSize        =   9.75
  24.       FontStrikethru  =   0   'False
  25.       FontUnderline   =   0   'False
  26.       Height          =   555
  27.       Left            =   60
  28.       TabIndex        =   22
  29.       Top             =   4860
  30.       Width           =   1515
  31.    End
  32.    Begin Frame Frame2 
  33.       Caption         =   "VB &Destination"
  34.       Height          =   615
  35.       Left            =   6960
  36.       TabIndex        =   18
  37.       Top             =   4800
  38.       Width           =   2175
  39.       Begin OptionButton DestImage 
  40.          Caption         =   ".Image"
  41.          Height          =   255
  42.          Left            =   1200
  43.          TabIndex        =   20
  44.          Top             =   240
  45.          Width           =   855
  46.       End
  47.       Begin OptionButton DestPicture 
  48.          Caption         =   ".Picture"
  49.          Height          =   255
  50.          Left            =   120
  51.          TabIndex        =   19
  52.          Top             =   240
  53.          Value           =   -1  'True
  54.          Width           =   975
  55.       End
  56.    End
  57.    Begin Frame Frame1 
  58.       Caption         =   "VB &Source"
  59.       Height          =   615
  60.       Left            =   1680
  61.       TabIndex        =   15
  62.       Top             =   4800
  63.       Width           =   2175
  64.       Begin OptionButton SrcImage 
  65.          Caption         =   ".Image"
  66.          Height          =   255
  67.          Left            =   1200
  68.          TabIndex        =   17
  69.          Top             =   240
  70.          Width           =   855
  71.       End
  72.       Begin OptionButton SrcPicture 
  73.          Caption         =   ".Picture"
  74.          Height          =   255
  75.          Left            =   120
  76.          TabIndex        =   16
  77.          Top             =   240
  78.          Value           =   -1  'True
  79.          Width           =   975
  80.       End
  81.    End
  82.    Begin ComboBox BltMode 
  83.       Height          =   300
  84.       Left            =   4080
  85.       Style           =   2  'Dropdown List
  86.       TabIndex        =   34
  87.       Top             =   4680
  88.       Width           =   2535
  89.    End
  90.    Begin CheckBox GDIRefresh 
  91.       Caption         =   "&GDI Draw Auto-Refresh"
  92.       Height          =   315
  93.       Index           =   2
  94.       Left            =   6660
  95.       TabIndex        =   36
  96.       Top             =   4500
  97.       Width           =   2355
  98.    End
  99.    Begin CheckBox GDIRefresh 
  100.       Caption         =   "&GDI Draw Auto-Refresh"
  101.       Height          =   315
  102.       Index           =   1
  103.       Left            =   1680
  104.       TabIndex        =   31
  105.       Top             =   4500
  106.       Width           =   2355
  107.    End
  108.    Begin CommandButton PopOver 
  109.       Caption         =   "Pop Over..."
  110.       Height          =   495
  111.       Left            =   60
  112.       TabIndex        =   21
  113.       Top             =   4320
  114.       Width           =   1515
  115.    End
  116.    Begin PictureBox ColorSet 
  117.       AutoRedraw      =   -1  'True
  118.       Height          =   255
  119.       Index           =   2
  120.       Left            =   8100
  121.       ScaleHeight     =   225
  122.       ScaleWidth      =   465
  123.       TabIndex        =   38
  124.       Top             =   4230
  125.       Width           =   495
  126.    End
  127.    Begin CheckBox AutoRedrawPic 
  128.       Caption         =   "&AutoRedraw"
  129.       Height          =   255
  130.       Index           =   2
  131.       Left            =   6660
  132.       TabIndex        =   14
  133.       Top             =   4260
  134.       Width           =   1335
  135.    End
  136.    Begin PictureBox ColorSet 
  137.       AutoRedraw      =   -1  'True
  138.       Height          =   255
  139.       Index           =   1
  140.       Left            =   3180
  141.       ScaleHeight     =   225
  142.       ScaleWidth      =   465
  143.       TabIndex        =   37
  144.       Top             =   4230
  145.       Width           =   495
  146.    End
  147.    Begin CheckBox AutoRedrawPic 
  148.       Caption         =   "&AutoRedraw"
  149.       Height          =   255
  150.       Index           =   1
  151.       Left            =   1680
  152.       TabIndex        =   13
  153.       Top             =   4260
  154.       Width           =   1335
  155.    End
  156.    Begin CommandButton Image2Picture 
  157.       Caption         =   "Image-->Picture"
  158.       Height          =   375
  159.       Index           =   2
  160.       Left            =   4620
  161.       TabIndex        =   30
  162.       Top             =   3840
  163.       Width           =   1695
  164.    End
  165.    Begin CommandButton Image2Picture 
  166.       Caption         =   "Image-->Picture"
  167.       Height          =   375
  168.       Index           =   1
  169.       Left            =   60
  170.       TabIndex        =   33
  171.       Top             =   3840
  172.       Width           =   1695
  173.    End
  174.    Begin CommandButton HideShow 
  175.       Caption         =   "Hide Picture -->"
  176.       Height          =   375
  177.       Index           =   2
  178.       Left            =   4620
  179.       TabIndex        =   29
  180.       Top             =   3360
  181.       Width           =   1695
  182.    End
  183.    Begin CommandButton HideShow 
  184.       Caption         =   "Hide Picture -->"
  185.       Height          =   375
  186.       Index           =   1
  187.       Left            =   60
  188.       TabIndex        =   28
  189.       Top             =   3360
  190.       Width           =   1695
  191.    End
  192.    Begin CommandButton FromClip 
  193.       Caption         =   "From Clipboard -->"
  194.       Height          =   375
  195.       Index           =   2
  196.       Left            =   4620
  197.       TabIndex        =   12
  198.       Top             =   2880
  199.       Width           =   1695
  200.    End
  201.    Begin CommandButton FromClip 
  202.       Caption         =   "From Clipbrd -->"
  203.       Height          =   375
  204.       Index           =   1
  205.       Left            =   60
  206.       TabIndex        =   5
  207.       Top             =   2880
  208.       Width           =   1695
  209.    End
  210.    Begin CommandButton ToClip 
  211.       Caption         =   "To Clipboard -->"
  212.       Height          =   375
  213.       Index           =   2
  214.       Left            =   4620
  215.       TabIndex        =   11
  216.       Top             =   2520
  217.       Width           =   1695
  218.    End
  219.    Begin CommandButton ToClip 
  220.       Caption         =   "To Clipboard -->"
  221.       Height          =   375
  222.       Index           =   1
  223.       Left            =   60
  224.       TabIndex        =   4
  225.       Top             =   2520
  226.       Width           =   1695
  227.    End
  228.    Begin CommandButton VB_Transfer_P1toP2 
  229.       Caption         =   ">-- VB Transfer -->"
  230.       Height          =   375
  231.       Left            =   4620
  232.       TabIndex        =   10
  233.       Top             =   2040
  234.       Width           =   1695
  235.    End
  236.    Begin CommandButton GdiDraw_P1 
  237.       Caption         =   "VB Draw Mode"
  238.       Height          =   375
  239.       Left            =   60
  240.       TabIndex        =   3
  241.       Top             =   2040
  242.       Width           =   1695
  243.    End
  244.    Begin CommandButton BitBlt_P1toP2 
  245.       Caption         =   ">-- BitBlt -->"
  246.       Height          =   375
  247.       Left            =   4620
  248.       TabIndex        =   9
  249.       Top             =   1680
  250.       Width           =   1695
  251.    End
  252.    Begin CommandButton Blt2Image 
  253.       Caption         =   "BitBlt --> Image"
  254.       Height          =   375
  255.       Left            =   60
  256.       TabIndex        =   32
  257.       Top             =   1680
  258.       Width           =   1695
  259.    End
  260.    Begin CommandButton SavePic 
  261.       Caption         =   "SavePicture()..."
  262.       Height          =   375
  263.       Index           =   2
  264.       Left            =   4620
  265.       TabIndex        =   40
  266.       Top             =   1200
  267.       Width           =   1695
  268.    End
  269.    Begin CommandButton SavePic 
  270.       Caption         =   "SavePicture()..."
  271.       Height          =   375
  272.       Index           =   1
  273.       Left            =   60
  274.       TabIndex        =   39
  275.       Top             =   1200
  276.       Width           =   1695
  277.    End
  278.    Begin CommandButton VB_LoadPic 
  279.       Caption         =   "LoadPicture()..."
  280.       Height          =   375
  281.       Index           =   2
  282.       Left            =   4620
  283.       TabIndex        =   7
  284.       Top             =   840
  285.       Width           =   1695
  286.    End
  287.    Begin CommandButton VB_LoadPic 
  288.       Caption         =   "LoadPicture()..."
  289.       Height          =   375
  290.       Index           =   1
  291.       Left            =   60
  292.       TabIndex        =   1
  293.       Top             =   840
  294.       Width           =   1695
  295.    End
  296.    Begin CommandButton VB_Refresh 
  297.       Caption         =   "VB Refresh  -->"
  298.       Height          =   375
  299.       Index           =   2
  300.       Left            =   4620
  301.       TabIndex        =   8
  302.       Top             =   420
  303.       Width           =   1695
  304.    End
  305.    Begin CommandButton VB_Refresh 
  306.       Caption         =   "VB Refresh  -->"
  307.       Height          =   375
  308.       Index           =   1
  309.       Left            =   60
  310.       TabIndex        =   2
  311.       Top             =   420
  312.       Width           =   1695
  313.    End
  314.    Begin PictureBox P2 
  315.       Height          =   4095
  316.       Left            =   6360
  317.       ScaleHeight     =   271
  318.       ScaleMode       =   3  'Pixel
  319.       ScaleWidth      =   183
  320.       TabIndex        =   23
  321.       Top             =   120
  322.       Width           =   2775
  323.    End
  324.    Begin PictureBox P1 
  325.       Height          =   4095
  326.       Left            =   1800
  327.       ScaleHeight     =   271
  328.       ScaleMode       =   3  'Pixel
  329.       ScaleWidth      =   183
  330.       TabIndex        =   25
  331.       Top             =   120
  332.       Width           =   2775
  333.    End
  334.    Begin CommandButton VB_Cls 
  335.       Caption         =   "VB Cls -->"
  336.       Height          =   375
  337.       Index           =   2
  338.       Left            =   4620
  339.       TabIndex        =   6
  340.       Top             =   60
  341.       Width           =   1695
  342.    End
  343.    Begin CommandButton VB_Cls 
  344.       Caption         =   "VB Cls -->"
  345.       Height          =   375
  346.       Index           =   1
  347.       Left            =   60
  348.       TabIndex        =   0
  349.       Top             =   60
  350.       Width           =   1695
  351.    End
  352.    Begin Label Status 
  353.       Alignment       =   2  'Center
  354.       BackColor       =   &H00C0C0C0&
  355.       FontBold        =   -1  'True
  356.       FontItalic      =   0   'False
  357.       FontName        =   "MS Sans Serif"
  358.       FontSize        =   9.75
  359.       FontStrikethru  =   0   'False
  360.       FontUnderline   =   0   'False
  361.       Height          =   375
  362.       Left            =   3960
  363.       TabIndex        =   24
  364.       Top             =   5040
  365.       Width           =   2895
  366.    End
  367.    Begin Label Label3 
  368.       Caption         =   "&Blt Mode:"
  369.       Height          =   195
  370.       Left            =   4980
  371.       TabIndex        =   35
  372.       Top             =   4440
  373.       Width           =   855
  374.    End
  375.    Begin Label Label2 
  376.       Alignment       =   2  'Center
  377.       Caption         =   "^ P2"
  378.       Height          =   255
  379.       Left            =   8640
  380.       TabIndex        =   27
  381.       Top             =   4260
  382.       Width           =   495
  383.    End
  384.    Begin Label Label1 
  385.       Alignment       =   2  'Center
  386.       Caption         =   "^ P1"
  387.       Height          =   255
  388.       Left            =   3900
  389.       TabIndex        =   26
  390.       Top             =   4260
  391.       Width           =   555
  392.    End
  393. Dim Draw As Integer '-- drawing on or off
  394. Dim GDI As Integer  '-- GDI=TRUE if drawing with GDI calls otherwise with VB methods
  395. Sub AutoRedrawPic_Click (Index As Integer)
  396. If Index = 1 Then
  397.     P1.AutoRedraw = (AutoRedrawPic(1).Value = 1)
  398.     P2.AutoRedraw = (AutoRedrawPic(2).Value = 1)
  399. End If
  400. End Sub
  401. Sub BitBlt_P1toP2_Click ()
  402. '-- BitBlt the entire area of P1 to P2
  403. Result = BitBlt(P2.hDC, 0, 0, P2.ScaleWidth, P2.ScaleHeight, P1.hDC, 0, 0, BltModeArray(BltMode.ListIndex))
  404. Status.Caption = "P1 BitBltted to P2"
  405. '-- if the GDIRefresh box is checked, then refresh P2
  406. If GDIRefresh(2).Value = 1 Then P2.Refresh
  407. End Sub
  408. Sub Blt2Image_Click ()
  409. 'BitBlt Screen to Image [from Keith Funk (72240,2020)]
  410. If P1.AutoRedraw = True Then
  411.     P1.AutoRedraw = False    'point to hDC of screen.
  412.     hScreenDC = P1.hDC       'save it.
  413.     P1.AutoRedraw = True     'point to hDC of Image.
  414.     Result = BitBlt(P1.hDC, 0, 0, P1.ScaleWidth, P1.ScaleHeight, hScreenDC, 0, 0, BltModeArray(BltMode.ListIndex))
  415.     hScreenDC = P1.hDC       'get hDC of Screen.
  416.     P1.AutoRedraw = True     'point to hDC of Image.
  417.     Result = BitBlt(P1.hDC, 0, 0, P1.ScaleWidth, P1.ScaleHeight, hScreenDC, 0, 0, BltModeArray(BltMode.ListIndex))
  418.     P1.AutoRedraw = False
  419. End If
  420. Status.Caption = "P1 BitBltted to Itself"
  421. '-- check if we should auto refresh after the bitblt
  422. If GDIRefresh(1).Value = 1 Then P1.Refresh
  423. End Sub
  424. Sub ColorSet_Click (Index As Integer)
  425. If Index = 1 Then
  426.     ColorSet P1
  427.     ColorSet P2
  428. End If
  429. End Sub
  430. Sub Form_Load ()
  431. '-- move the form to the upper left
  432. Move 0, 0
  433. '-- load the Blt Raster-OPs into the combo box for selection
  434. BltMode.AddItem "SrcCopy"
  435. BltMode.AddItem "SrcPaint"
  436. BltMode.AddItem "SrcAND"
  437. BltMode.AddItem "SrcInvert"
  438. BltMode.AddItem "SrcErase"
  439. BltMode.AddItem "NOTSrcCopy"
  440. BltMode.AddItem "NOTSrcErase"
  441. BltMode.AddItem "MergeCopy"
  442. BltMode.AddItem "MergePaint"
  443. BltMode.AddItem "PatCopy"
  444. BltMode.AddItem "PatPaint"
  445. BltMode.AddItem "PatInvert"
  446. BltMode.AddItem "DstInvert"
  447. BltMode.AddItem "Blackness"
  448. BltMode.AddItem "Whiteness"
  449. BltMode.ListIndex = 0
  450. BltModeArray(0) = SRCCOPY
  451. BltModeArray(1) = SRCPAINT
  452. BltModeArray(2) = SRCAND
  453. BltModeArray(3) = SRCINVERT
  454. BltModeArray(4) = SRCERASE
  455. BltModeArray(5) = NOTSRCCOPY
  456. BltModeArray(6) = NOTSRCERASE
  457. BltModeArray(7) = MERGECOPY
  458. BltModeArray(8) = MERGEPAINT
  459. BltModeArray(9) = PATCOPY
  460. BltModeArray(10) = PATPAINT
  461. BltModeArray(11) = PATINVERT
  462. BltModeArray(12) = DSTINVERT
  463. BltModeArray(13) = BLACKNESS
  464. BltModeArray(14) = WHITENESS
  465. For i = 1 To 2
  466.     ColorSet(i).Cls
  467.     ColorSet(i).ScaleMode = 3  '-- Pixels
  468.     ColorWid = ColorSet(i).ScaleWidth \ 3
  469.     ColorHgt = ColorSet(i).ScaleHeight
  470.     ColorSet(i).Line (0, 0)-(ColorWid, ColorHgt), &HFF0000, BF
  471.     ColorSet(i).Line (ColorWid + 1, 0)-(ColorWid * 2, ColorHgt), &HFF00&, BF
  472.     ColorSet(i).Line (ColorWid * 2 + 1, 0)-(ColorWid * 3 + 2, ColorHgt), &HFF&, BF
  473. End Sub
  474. Sub FromClip_Click (Index As Integer)
  475. If Index = 1 Then
  476.     P1.Picture = ClipBoard.GetData()
  477.     Status.Caption = "P1.Picture=ClipBoard"
  478.     P2.Picture = ClipBoard.GetData()
  479.     Status.Caption = "P2.Picture=ClipBoard"
  480. End If
  481. End Sub
  482. Sub GdiDraw_P1_Click ()
  483. If GDI Then
  484.     GDI = False
  485.     GDIDraw_P1.Caption = "VB Draw Mode"
  486.     Status.Caption = "Now in VB Draw Mode"
  487.     GDI = True
  488.     GDIDraw_P1.Caption = "GDI Draw Mode"
  489.     Status.Caption = "Now in GDI Draw Mode"
  490. End If
  491. End Sub
  492. Sub HideShow_Click (Index As Integer)
  493. If HideShow(Index).Caption = "Hide Picture -->" Then
  494.     HideShow(Index).Caption = "Show Picture -->"
  495.     Stat$ = "Hidden"
  496. Else '-- it's already hidden and we'll be showing it
  497.     HideShow(Index).Caption = "Hide Picture -->"
  498.     Stat$ = "Visible"
  499. End If
  500. If Index = 1 Then '-- change P1's visible property
  501.     P1.Visible = Not P1.Visible
  502.     Status.Caption = "P1 is now " + Stat$
  503.     P2.Visible = Not P2.Visible
  504.     Status.Caption = "P2 is now " + Stat$
  505. End If
  506. End Sub
  507. Sub Image2Picture_Click (Index As Integer)
  508. If Index = 1 Then
  509.     P1.Picture = P1.Image
  510.     P2.Picture = P2.Image
  511. End If
  512. Pic$ = "P" + Format$(Index)
  513. Status.Caption = Pic$ + ".Picture=" + Pic$ + ".Image"
  514. End Sub
  515. Sub P1_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
  516. Draw = True
  517. If GDI Then
  518.     '-- set the pixel to black
  519.     R& = SetPixel(P1.hDC, x, y, 0&)
  520.     '-- move the current position for later LineTo's
  521.     R& = MoveTo(P1.hDC, x, y)
  522.     Status.Caption = "GDI Draw Started in P1"
  523.     P1.PSet (x, y)
  524.     Status.Caption = "VB Draw Started in P1"
  525. End If
  526. End Sub
  527. Sub P1_MouseMove (Button As Integer, Shift As Integer, x As Single, y As Single)
  528. If Draw Then
  529.     If GDI Then
  530.         R% = LineTo(P1.hDC, x, y)
  531.         If GDIRefresh(1).Value = 1 Then P1.Refresh
  532.     Else
  533.         P1.Line -(x, y)
  534.     End If
  535. End If
  536. End Sub
  537. Sub P1_MouseUp (Button As Integer, Shift As Integer, x As Single, y As Single)
  538. Draw = False
  539. If GDI Then
  540.     Status.Caption = "GDI Draw Stopped in P1"
  541.     Status.Caption = "VB Draw Stopped in P1"
  542. End If
  543. End Sub
  544. Sub PopOver_Click ()
  545. PopOverForm.Show MODAL
  546. End Sub
  547. Sub Quit_Click ()
  548. End Sub
  549. Sub ToClip_Click (Index As Integer)
  550. ClipBoard.Clear
  551. If Index = 1 Then
  552.     If SrcPicture.Value Then '-- copy the .Picture property to the ClipBoard
  553.         ClipBoard.SetData (P1.Picture)
  554.         Status.Caption = "ClipBoard=P1.Picture"
  555.     Else    '-- copy the .Image property to the ClipBoard
  556.         ClipBoard.SetData (P1.Image)
  557.         Status.Caption = "ClipBoard=P1.Image"
  558.     End If
  559.     If DestPicture.Value Then '-- copy the .Picture property to the ClipBoard
  560.         ClipBoard.SetData (P2.Picture)
  561.         Status.Caption = "ClipBoard=P2.Picture"
  562.     Else    '-- copy the .Image property to the ClipBoard
  563.         ClipBoard.SetData (P2.Image)
  564.         Status.Caption = "ClipBoard=P2.Image"
  565.     End If
  566. End If
  567. End Sub
  568. Sub VB_Cls_Click (Index As Integer)
  569. If Index = 1 Then
  570.     P1.Cls
  571.     P2.Cls
  572. End If
  573. Status.Caption = "Picture " + Format$(Index) + " CLSed"
  574. End Sub
  575. Sub VB_LoadPic_Click (Index As Integer)
  576. ' Before calling FOPEN.FRM we can specify a new pattern
  577. ' (ThePattern) a new path (ThePath) and a different
  578. ' Form Title.  Change FullName to an empty string.
  579. FullName = ""
  580. '-- we want to load either BMPs or WMFs, ICOs can't be used
  581. ThePattern = "*.BMP;*.WMF"
  582. FormTitle = "LoadPicture() Selection"
  583. ' We want to show the form Modal and Unload it after completion
  584. ' (no reason to waste resources).  Since the variables are
  585. ' global, we can unload it without worrying about referencing
  586. ' properties in an unloaded form, which would cause it to reload
  587. FOpenForm.Show MODAL
  588. Unload FOpenForm
  589. If FullName = "CANCEL" Then Exit Sub
  590. '-- note that if no filename was selected, FullName will
  591. '   be null, which is OK with us because it'll mean that
  592. '   we should just do a LoadPicture()
  593. If Index = 1 Then
  594.     P1.Picture = LoadPicture(FullName)
  595.     P2.Picture = LoadPicture(FullName)
  596. End If
  597. Status.Caption = "P" + Format$(Index) + ".Picture=LoadPicture()"
  598. End Sub
  599. Sub VB_Refresh_Click (Index As Integer)
  600. If Index = 1 Then
  601.     P1.Refresh
  602.     P2.Refresh
  603. End If
  604. Status.Caption = "P" + Format$(Index) + " Refreshed"
  605. End Sub
  606. Sub VB_Transfer_P1toP2_Click ()
  607. If SrcPicture.Value Then
  608.     P2.Picture = P1.Picture
  609.     Status.Caption = "P2.Picture = P1.Picture"
  610.     P2.Picture = P1.Image
  611.     Status.Caption = "P2.Picture = P1.Image"
  612. End If
  613. End Sub
  614.